﻿using ProductMonitor.Commands;
using ProductMonitor.UserControls;
using ProductMonitor.View;
using ProductMonitor.ViewModel;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ProductMonitor
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        // 这次需要把视图模型里面的属性改掉，所以先设为全局变量
        MainWindowVM vm = new MainWindowVM();
        public MainWindow()
        {
            InitializeComponent();

            this.DataContext = vm;
        }

        // 换用户控件：只需把MonitorUC这个用户控件换掉就行
        // 车间详情页面展示
        private void ShowDetailUC()
        {
            WorkShopDetailUC workShopDetailUC = new WorkShopDetailUC();
            vm.MonitorUC = workShopDetailUC;


            //动画效果(由下而上)
            //位移 移动时间
            ThicknessAnimation thicknessAnimation = new ThicknessAnimation(new Thickness(0, 50, 0, -50), new Thickness(0, 0, 0, 0), new TimeSpan(0, 0, 0, 0, 400));

            //透明度
            DoubleAnimation doubleAnimation = new DoubleAnimation(0, 1, new TimeSpan(0, 0, 0, 0, 400));

            // 将动画作用到用户定义控件上
            Storyboard.SetTarget(thicknessAnimation, workShopDetailUC);
            Storyboard.SetTarget(doubleAnimation, workShopDetailUC);

            // 定义动画目标属性
            Storyboard.SetTargetProperty(thicknessAnimation, new PropertyPath("Margin"));
            Storyboard.SetTargetProperty(doubleAnimation, new PropertyPath("Opacity"));

            // Storyboard用于控制动画的播放
            Storyboard storyboard = new Storyboard();
            storyboard.Children.Add(thicknessAnimation);
            storyboard.Children.Add(doubleAnimation);
            storyboard.Begin();

        }

        // 返回到主界面监控
        private void GoBackMonitor()
        {
            MonitorUC monitorUC = new MonitorUC();
            vm.MonitorUC = monitorUC;
        }


        // 如果通俗简单，直接将命令实例化写在WPF后端代码中，不必继续写在viewmodel中
        public OpCommand ShowDetailCommand
        {
            get
            {
                return new OpCommand(ShowDetailUC);
            }
        }
        
        public OpCommand GoBackCommand
        {
            get
            {
                return new OpCommand(GoBackMonitor);
            }
        }

        /// <summary>
        /// 三个按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnMin(object sender, RoutedEventArgs e)
        {
            this.WindowState = WindowState.Minimized;
        }

        private void BtnMax(object sender, RoutedEventArgs e)
        {
            if (this.WindowState == WindowState.Maximized)
            {
                this.WindowState = WindowState.Normal;
            }
            else
            {
                this.WindowState = WindowState.Maximized;
            }
        }

        private void BtnClose(object sender, RoutedEventArgs e)
        {
            Environment.Exit(0);
        }


        #region 显示配置窗口
        private void ShowSettingWin()
        {
            SettingWin settingWin = new SettingWin() { Owner = this };
            settingWin.ShowDialog();
        }

        public OpCommand ShowSettingCommand
        {
            get
            {
                return new OpCommand(ShowSettingWin);
            }
        }

        #endregion
    }
}